<template>
  <div class="login_page">
    <div class="lg_bg"></div>
    <el-form :model="ruleForm2" :rules="rules2" ref="ruleForm2" label-position="left" label-width="0px" class="demo-ruleForm login-container">
      <div class="lg_logo"></div>
      <h3 class="title">开开农场管理后台</h3>
      <el-form-item prop="account">
        <div class="adminName">
          <i class="fa fa-user-o"></i>
          <input type="text" v-model="ruleForm2.account" auto-complete="off" placeholder="后台管理账号" class="adminLogin" @keyup.enter="doLogin">
        </div>
      </el-form-item>
      <el-form-item prop="checkPass">
        <div class="adminName">
          <i class="fa fa-unlock-alt"></i>
          <input type="password" v-model="ruleForm2.checkPass" auto-complete="off" placeholder="密码" class="adminLogin" @keyup.enter="doLogin">
        </div>
      </el-form-item>
      <el-form-item style="width:100%;">
        <el-button type="success" style="width:100%;" @click.native.prevent="handleSubmit" :loading="logining">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script type="text/ecmascript-6">
  import { login } from '../apiTree'
  import NProgress from 'nprogress'

  export default {
    data() {
      return {
        logining: false,
        ruleForm2: {
          account: '',
          checkPass: ''
        },
        rules2: {
          account: [
            { required: true, message: '请输入账号', trigger: 'blur' }
          ],
          checkPass: [
            { required: true, message: '请输入密码', trigger: 'blur' }
          ]
        },
        checked: true
      }
    },
    methods: {
      handleReset2() {
        this.$refs.ruleForm2.resetFields()
      },
      handleSubmit() {
        this.$refs.ruleForm2.validate((valid) => {
          if (valid) {
            this.logining = true
            NProgress.start()
            let para = {'data': {username: this.ruleForm2.account, password: this.ruleForm2.checkPass}};
            login(para).then(data => {
              this.logining = false
              NProgress.done()
              if (data.s !== 1) {
                if (data.s === -4) {
                  this.$message({
                    message: '没有权限',
                    type: 'error'
                  })
                } else {
                  this.$message({
                    message: '账号密码错误',
                    type: 'error'
                  })
                }
              } else {
                this.$store.commit('setAdminer', data.d)
                  this.$router.push({ path: '/' })
              }
            })
          } else {
            return false
          }
        })
      },
      doLogin() {
        if (!this.ruleForm2.account) {
          this.$message.error('请输入账号！');
          return
        }
        if (!this.ruleForm2.checkPass) {
          this.$message.error('请输入密码！');
          return
        }
        this.handleSubmit();
      }
    },
    created() {}
  }

</script>

<style scoped lang="scss" scoped>
  .login_page .login-container[data-v-6ba26bd4] {
    width: 280px;
  }
  img {
    width: 100%;
    height: 100%;
  }
  .login_page {
    position: relative;
    overflow: hidden;
    height: 100%;
    .lg_bg {
      height: 1000px;
      background: url('http://kkfarm.image.alimmdn.com/web/reg_back.png@20.jpg') no-repeat 50% 50%;
      background-size: cover;
      width: 100%;
      position: absolute;
      left: 0;
      top: 0;
      z-index: -1;
    }
    .lg_logo {
      width: 100px;
      height: 100px;
      background: url("../../static/images/logo.png") no-repeat;
      margin:auto;
      margin-bottom: 20px;
    }
    .login-container {
      /*box-shadow: 0 0px 8px 0 rgba(0, 0, 0, 0.06), 0 1px 0px 0 rgba(0, 0, 0, 0.02);*/
      -webkit-border-radius: 5px;
      border-radius: 5px;
      -moz-border-radius: 5px;
      background-clip: padding-box;
      margin-right: 20%;
      float: right;
      margin-top: 15%;
      width: 350px;
      padding: 40px 20px 40px 20px;
      background: #fff;
      border: 1px solid #eaeaea;
      box-shadow: 0 0 25px #cac6c6;
      .title {
        margin: 0px auto 40px auto;
        text-align: center;
        color: #505458;
      }
      .adminName {
        position: relative;
        .fa-user-o, .fa-unlock-alt {
          position: absolute;
          left: 10px;
          top: 12px;
          font-size: 18px;
          color: #999999;
        }

      .adminLogin {
          width: 270px;
          height: 28px;
          border: 1px;
          text-indent: 25px;
          border-radius: 5px;
          padding: 4px;
          border: solid 1px #E5E5E5;
          outline: 0;
          color: #999999;
          font: normal 13px/100% Verdana, Tahoma, sans-serif;
          background: #FFFFFF;
          box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 8px;
          -moz-box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 8px;
          -webkit-box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 8px;
        }
      }
    }
    .lg_foot {
      width: 1200px;
      margin: auto;
      margin-top: 800px;
      margin-bottom: 0px;
      border-top: 1px solid #d5d5d5;
      text-align: center;
      color: #999;
      padding-top: 30px;
    }
  }
</style>
